class Solution {
public:
    int minimumTotal(vector<vector<int>>& triangle) {
        int n = triangle.size();
        vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0x3f3f3f3f));
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1]) + triangle[i - 1][j - 1];
            }
        }
        int ret = 0x3f3f3f3f;
        for (int i = 1; i <= n; i++)
        {
            ret = min(ret, dp[n][i]);
        }
        return ret;
    }
};